﻿using System;
using System.Collections.Generic;
using Hematology.Data;
using Hematology.Tools;
using Hematology.Tools.Storage;
using Hematology.Tools.Text;
using Hematology.UserSite.Controls;

namespace Hematology.UserSite.admin
{
	public partial class SendEmail : NgoPage
	{
		#region Properties

		#endregion

		#region Fill methods
		
		#endregion

		#region Other methods

		private void ToolbarSetup()
		{
			ckedEmailContent.config.skin = "office2003";
			ckedEmailContent.config.toolbar = PageHelper.EditorButtonSet;

			ckedEmailContent.DisableObjectResizing = true;
			ckedEmailContent.ResizeEnabled = false;
			ckedEmailContent.Width = 904;
		}

		#endregion

		#region Event handlers

		protected void Page_Load(object sender, EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				ToolbarSetup();
				mvSendEmail.ActiveViewIndex = 0;
			}
		}

		protected void btnSendEmail_Click(object sender, EventArgs e)
		{
			EmailTemplate etFreeEmail = EmailTemplate.GetEmailTemlateByType((int)EnumHelper.EmailTemplateType.FreeEmail);
			if (etFreeEmail == null)
				return;

			bool bIsAdminCopy = false;
			for (int siteUserIndex = 0; siteUserIndex < SessionHelper.UserList.Count; siteUserIndex++)
			{
				SiteUserExtended selectedUser = SessionHelper.UserList[siteUserIndex];

				if (siteUserIndex == 0)
					bIsAdminCopy = true;

				MailHelper.SendEmail(etFreeEmail, selectedUser.BaseInfo.Email, bIsAdminCopy, txtEmailSubject.Text,
				                     new[]
				                     	{
											selectedUser.FirstName,
											selectedUser.MiddleName,
				                     		ckedEmailContent.Text
				                     	});
			}
		}

		protected void btnList_Click(object sender, EventArgs e)
		{
			Response.Redirect("/admin/UserManagement.aspx?view=List");
		}

		#endregion
	}
}